import React from 'react';
import { connect } from 'umi';
import { RESUME_STEP_ENUM } from './enum';
import { Candidate, Hire, Interview, Resume } from './Buttons';

const buttonMap = {
    [RESUME_STEP_ENUM.RESUME]: Resume,
    [RESUME_STEP_ENUM.CANDIDATE]: Candidate,
    [RESUME_STEP_ENUM.HIRE]: Hire,
    [RESUME_STEP_ENUM.INTERVIEW]: Interview
};

const Operator = ({ record, onRefresh, user }) => {
    const Button = buttonMap[record?.resumeStep];
    if (!Button) return null;
    const { currentUser = {} } = user;
    const isLauncher = record?.launchEmployeeCode === currentUser.employeeCode;
    const isPrincipal = record?.principalEmployeeCode === currentUser.employeeCode;
    const buttonProps = {
        record,
        onRefresh,
        isLauncher,
        isPrincipal,
        user
    };
    return <Button {...buttonProps} />;
};

export default connect(({ user }) => ({ user }))(Operator);
